package com.braveman.im.ui.fragment;


import android.os.Bundle;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.braveman.im.R;
import com.braveman.im.bean.PersonalDataBaen;
import com.braveman.im.constant.Constants;
import com.braveman.im.ui.activity.CardActivity;
import com.braveman.im.ui.activity.DataItemActivity;
import com.braveman.im.ui.activity.IndexActivity;
import com.braveman.im.ui.activity.IntegrityActivity;
import com.braveman.im.ui.activity.MemberActivity;
import com.braveman.im.ui.activity.MyUnitsActivity;
import com.braveman.im.ui.activity.PersonalDataActivity;
import com.braveman.im.ui.activity.ResourceActivity;
import com.braveman.im.ui.activity.StateActivity;
import com.braveman.im.ui.activity.message.QrcodeForMineActivity;
import com.braveman.im.ui.activity.mine.GetMineFriendsAndGroupActivity;
import com.bumptech.glide.Glide;
import com.ht.baselibs.core.EventCode;
import com.ht.baselibs.ui.base.BaseFragment;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.SharedPreferencesUtils;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;

/**
 * 我的个人中心
 */
public class MineFragment extends BaseFragment {
    private TextView mineName;
    private TextView mineNumber;
    private QMUIRadiusImageView mineImg;
    private PersonalDataBaen personalDataBaen;
    private String user_id;
    private String cxh;

    @Override
    protected void initTitleBar() {
        super.initTitleBar();
        mTitleBarView.setLeftBtnIcon(R.mipmap.back_black).setOnLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }


    @Override
    protected View initContentView() {
        return LayoutInflater.from(mContext).inflate(R.layout.fragment_mine, null);
    }

    @Override
    protected void initChildView() {
        mineName = findViewById(R.id.fagment_tx_name);
        mineNumber = findViewById(R.id.fagment_tx_number);
        mineImg = findViewById(R.id.fragment_img_head);
        mineName.setText(SharedPreferencesUtils.getString(Constants.MINNAME, ""));
        cxh = SharedPreferencesUtils.getString(Constants.MINNUMBER, "");
        mineNumber.setText("诚信号:" + cxh);
        String titleAvtar = SharedPreferencesUtils.getString(Constants.MINIMG, "");
        if (!TextUtils.isEmpty(titleAvtar))
            mineImg.setCircle(false);
        Glide.with(mContext).load(titleAvtar).into(mineImg);
    }

    @Override
    protected void load() {

    }

//    @Override
//    protected void initArgumentsData(Bundle args) {
//        super.initArgumentsData(args);
//        ApiManager.getApi().getPersonalData().enqueue(new NetCallBack<PersonalDataBaen>() {
//            @Override
//            protected void onSuccess(Call<PersonalDataBaen> call, Response<PersonalDataBaen> response) {
//                personalDataBaen = response.body();
//                if (response != null) {
//                    mineName.setText(personalDataBaen.name);
//                    mineNumber.setText(personalDataBaen.sn);
//                }
//            }
//        });
//    }

    //初始化控件
    @Override
    protected void setChildViewListener() {
        findViewById(R.id.fragment_card).setOnClickListener(this);
        findViewById(R.id.fragment_dynamic).setOnClickListener(this);
        findViewById(R.id.fragment_unit).setOnClickListener(this);
        findViewById(R.id.fragment_member).setOnClickListener(this);
//        findViewById(R.id.fragment_order).setOnClickListener(this);
//        findViewById(R.id.fragment_resource).setOnClickListener(this);
        findViewById(R.id.fragment_img_head).setOnClickListener(this);
//        findViewById(R.id.activity_mine_QRcode).setOnClickListener(this);
//        findViewById(R.id.fragment_percentage).setOnClickListener(this);
        findViewById(R.id.frament_platform).setOnClickListener(this);
//        findViewById(R.id.fragment_setting).setOnClickListener(this);
//        findViewById(R.id.frament_exit).setOnClickListener(this);
        findViewById(R.id.frament_indent).setOnClickListener(this);
        findViewById(R.id.fragment_flock).setOnClickListener(this);
        findViewById(R.id.tv_activity_mine_friends).setOnClickListener(this);
        findViewById(R.id.fragment_resource).setOnClickListener(this);
        findViewById(R.id.fagment_img_two).setOnClickListener(this);
        //findViewById(R.id.fagment_tx_name).setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        Bundle bundle = new Bundle();
        switch (v.getId()) {
//            case R.id.frament_indent:
//                ActivityUtils.startActivity(mContext, ComplainActivity.class); //投诉
//                break;
            case R.id.fragment_img_head:
                ActivityUtils.startActivity(mContext, DataItemActivity.class);//头像
                break;
            case R.id.fragment_card:
                ActivityUtils.startActivity(mContext, CardActivity.class);//名片
                break;
            case R.id.frament_indent:
                ActivityUtils.startActivity(mContext, IndexActivity.class);//诚信指数
                break;
            case R.id.fragment_dynamic:
                ActivityUtils.startActivity(mContext, StateActivity.class);//我的动态
                break;
            case R.id.fragment_unit:
                ActivityUtils.startActivity(mContext, MyUnitsActivity.class);//我的单位
                break;
            case R.id.fragment_resource:
                ActivityUtils.startActivity(mContext, ResourceActivity.class);//我的资源
                break;
            case R.id.fragment_member:
                ActivityUtils.startActivity(mContext, MemberActivity.class);//会员
                break;
            case R.id.frament_platform:
                bundle.putString("id", cxh);
                ActivityUtils.startActivity(mContext, IntegrityActivity.class, bundle);//我的平台
                break;
//            case R.id.fragment_setting:
//                           ActivityUtils.startActivity(mContext, SettingActivity.class);//设置
//                break;
//            case R.id.frament_exit:
//                ActivityUtils.startActivity(mContext, AnnouncementActivity.class);//群公告
//                break;
            case R.id.tv_activity_mine_friends://我的好友
                bundle.putInt("listType", 3);//1群 2 单位 3好友
                ActivityUtils.startActivity(mContext, GetMineFriendsAndGroupActivity.class, bundle);//我的好友
                break;
            case R.id.fragment_flock:
                bundle.putInt("listType", 1);//我的群
                ActivityUtils.startActivity(mContext, GetMineFriendsAndGroupActivity.class, bundle);
                break;
            case R.id.fagment_img_two:
                //  bundle.putInt("type", 1);
                bundle.putString("qrCodeType", cxh);
                ActivityUtils.startActivity(mContext, QrcodeForMineActivity.class, bundle);//我的二维码
                break;
        }
    }

    @Override
    protected void onVisible() {
    }

    @Override
    protected boolean hasEvent() {
        return true;
    }

    @Override
    protected void onEvent(int eventCode, Object data) {
        switch (eventCode) {
            case EventCode.EVENT_CHANGE_AVATAR:
                String titleAvtar = SharedPreferencesUtils.getString(Constants.MINIMG, "");
                if (!TextUtils.isEmpty(titleAvtar))
                    Glide.with(mContext).load(titleAvtar).into(mineImg);
                break;
            case EventCode.EVENT_CHANGE_NAME:
                cxh = SharedPreferencesUtils.getString(Constants.MINNUMBER, "");
                if (!TextUtils.isEmpty(cxh))
                    mineNumber.setText("诚信号:" + cxh);
                break;
        }
    }
}
